package com.qimo.zuoyeoa.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qimo.zuoyeoa.dao.MeetingMapper;
import com.qimo.zuoyeoa.entity.Meeting;
import com.qimo.zuoyeoa.service.MeetingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class MeetingServiceImpl implements MeetingService {
    @Autowired
    private MeetingMapper meetingMapper;
    @Override
    public Meeting findByNamePass(String meetingname, String password) {
        return meetingMapper.selectByNamePass(meetingname,password);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean append(Meeting meeting) {
        return meetingMapper.insert(meeting) > 0;
    }

    @Override
    public PageInfo<Meeting> findAll(int pageNum, int pageSize) {

        PageHelper.startPage(pageNum,pageSize);
        final List<Meeting> meetings = meetingMapper.selectAll();
        PageInfo<Meeting> pageInfo = new PageInfo<>(meetings);
        return pageInfo;
    }

    @Override
    public PageInfo<Meeting> findByKeyword(int pageNum, int pageSize, String keyword) {
        PageHelper.startPage(pageNum, pageSize);
        List<Meeting> meetings = meetingMapper.selectByKeyword(keyword);
        PageInfo<Meeting> pageInfo = new PageInfo<>(meetings);
        return pageInfo;
    }

    @Override
    public Meeting findById(int id) {
        return meetingMapper.selectById(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean modify(Meeting meeting) {
        return meetingMapper.updateById(meeting)>0;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean remove(int id) {
        return meetingMapper.deleteById(id) > 0;
    }

    @Override
    public List<Meeting> findAll() {
        return meetingMapper.selectAll();
    }
}
